/* 
 * File:   main.cpp
 * Author: eddieteo
 *
 * Created on January 29, 2012, 8:58 PM
 */
#include "Topic.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <iomanip>

using namespace std;

int main() 
{
    Topic t;
    int choice;

    bool exit = false;
    while (!exit)
    
    {
        cout << "Online FeedBack System Topic" << endl; // Display Program for output
        cout << "============================" << endl;
        cout << "1) Create Topic " << endl;
        cout << "2) Show   Topic " << endl;
        cout << "3) Exit" << endl;
 
        cout << "Select your choice: "; // Enter the choice
        cin >> choice;
        cout << endl << "";

        switch (choice) // selection of choice
        {
            case 1:
            {   
                t.CreateTopic(); // CreatTopic Function
                break;
            }
            
            case 2:
            {                  
                t.ShowTopic(); // ShowTopic Function
                break;
            }
            
            case 3:
            {
                exit = true; // Hit 3 and will exit the program
                
                break;
            }
        }
    }
    return 0;
}
              
void Topic::CreateTopic()
{          
            ofstream file;
            file.open("Topic.txt", ofstream:: app);
            
            cout << "Topic 1" << endl ;
            cin  >> TopicName;
            cout << "Description" << endl ;
            cin  >> TopicDescription;
            
            cout << endl << "Topic 1" << endl << TopicName << endl << "Description" << endl << TopicDescription << endl;
            file << endl << "Topic 1" << endl << TopicName << endl << "Description" << endl << TopicDescription << endl;
                
            cout << endl << "Text File created" << endl << endl;
            file.close();
                        
}

void Topic::ShowTopic()
{
    bool test = false;

    cout << endl << "Please enter the filename: ";

    while (test == false) 
    {
        cin >> fileName;

        ifstream file;
        string ans;
        file.open(fileName.c_str());
        if (file.is_open()) 
        {
            string data;
            while(file.good())
            {
                getline(file, data);
                ans += data +'\n';        
            }
            cout << ans << endl;
        }

        file.close();
        test = true;
    }
}
